#include <iostream>
#include <string>
#include <fstream>
#include <istream>
#include <sstream>
#include <map>
using namespace std;
bool is_word(const string & word){
   //判断是否为单词
   auto it = word.begin();
   while(it !=word.end()){
       if(!isalpha(*it)){
           return false;
       }
       ++it;
   }
   return true;
}
class Dictionary{
public:
    void read(const string & filename){
       ifstream ifs(filename);
       string line;
       while(getline(ifs,line)){
          istringstream iss(line);
          string word;
          while(iss >> word){
              if(is_word(word)){
                  if(_dict.count(word) == 1){
                  //表示_dict里面有word这个元素,计数加1 
                   ++_dict[word];
                  }else{
                      _dict.insert({word,1});
                  }
                  }
              }
          }
       }
    void store(const string & filename){
        ofstream ofs(filename);
        for(auto & dict : _dict){
           ofs<<dict.first<<":"<<dict.second<<endl;
        }
        ofs.close();
    }
private:
    map<string,int> _dict;
};
void test(){
     Dictionary dict;
     dict.read("The_Holy_Bible.txt");
     dict.store("count.txt");
}
int main()
{
    test();
    return 0;
}

